package com.hxd.otc.module.convenience.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.convenience.bean.ConvenienveHistoryBean;
import com.hxd.otc.module.convenience.bean.NorGoodsBean;
import com.hxd.otc.module.convenience.contract.OilRechargeContract;
import com.hxd.otc.module.convenience.model.ConvenienceModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;
import java.util.List;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/4 17:02
 * 描  述 :  ${所有订单页面}
 */
public class OilRechargePresenter extends BasePresenter<OilRechargeContract.View> implements OilRechargeContract.Presenter {

    ConvenienceModel model;

    public OilRechargePresenter(OilRechargeContract.View view) {
        super(view);
        model = ConvenienceModel.getInstance();
    }

    @Override
    public void onLoadRmb(String id) {

        model.getGoodsList(id, new BaseObserver<ArrayList<NorGoodsBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<NorGoodsBean> norGoodsBeans) {
                doSetRMBAdapter(norGoodsBeans);
                doRMBShowNoMore();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ArrayList<NorGoodsBean>>>bindAutoDispose());
    }

    @Override
    public void onLoadHistory(String id) {

        model.getHistoryList(id, new BaseObserver<ArrayList<ConvenienveHistoryBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<ConvenienveHistoryBean> convenienveHistoryBeans) {
                doSetHistoryAdapter(convenienveHistoryBeans);
                doHistoryShowNoMore();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ArrayList<ConvenienveHistoryBean>>>bindAutoDispose());
    }

    @Override
    public void onDelete(String flagType) {
        model.deleteFlagType(flagType, new BaseObserver() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.onDeleteSucced();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose());
    }

    @Override
    public void doSetRMBAdapter(List<NorGoodsBean> list) {

        mView.onSetRMBAdapter(list);
    }

    @Override
    public void doSetHistoryAdapter(List<ConvenienveHistoryBean> list) {

        mView.onSetHistoryAdapter(list);
    }


    @Override
    public void doRMBShowNoMore() {

        mView.onRMBShowNoMore();
    }

    @Override
    public void doHistoryShowNoMore() {
        mView.onHistoryShowNoMore();
    }
}
